package psn.kiko.config.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * redis数据库配置
 */
@Configuration
@Slf4j
public class RedisConfiguration{
	
	@Bean
	public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
		log.debug("开始配置redis模板对象...");
		RedisTemplate redisTemplate=new RedisTemplate();
		redisTemplate.setConnectionFactory(redisConnectionFactory);
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		return redisTemplate;
	}
	
	//指定销毁回调方法cleanCache
	@Bean(destroyMethod="cleanCache")
	public CleanRedisCache cleanRedisCache(RedisTemplate redisTemplate){
		CleanRedisCache cleanRedisCache=new CleanRedisCache();
		cleanRedisCache.setRedisTemplate(redisTemplate);
		return cleanRedisCache;
	}
}
